#!/usr/bin/env php
<?php
use WondPHP\App;
use WondPHP\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use  WondPHP\ErrorHandel;

if (false === in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) {
    echo 'Warning: The console should be invoked via the CLI version of PHP, not the '.\PHP_SAPI.' SAPI'.\PHP_EOL;
}

set_time_limit(0);

require __DIR__.'/vendor/autoload.php';

$input = new ArgvInput();
if (null !== $env = $input->getParameterOption(['--env', '-e'], null, true)) {
    putenv('APP_ENV='.$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = $env);
}

if ($input->hasParameterOption('--no-debug', true)) {
    putenv('APP_DEBUG='.$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '0');
}
define('BASE_PATH', __DIR__);
define('DEBUG',env('APP_DEBUG'));
 
if (DEBUG) {
    umask(0000);
    (new WondPHP\ErrorHandel());
}

$kernel = new App();
$application = new Application($kernel);
$application->run($input);
